package com.kele.utils;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.kele.R;
import com.kele.bean.Bean;

import java.util.List;

public class MyAdapter extends BaseAdapter {



    private List<Bean> data;
    private Context context;

    public MyAdapter(List<Bean> data,Context context) {
        this.data=data;
        this.context=context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;

        if (convertView==null){
            viewHolder=new ViewHolder();
            convertView=LayoutInflater .from(context).inflate(R.layout.list_item,parent,false);
            viewHolder.textView=convertView.findViewById(R.id.tv);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(data.get(position).getName());

        Log.i("kele","getView"+position);

        return convertView;

    }

    private final class ViewHolder{
        TextView textView;
    }
}
